package com.person.blog.utils;


import com.person.blog.common.ErrorCode;
import com.person.blog.config.BusineseException;

import java.util.Date;

public class CommonUtils {

    public static void checkNull(Object object, ErrorCode errorCode, String msg) {
        if (object == null) {
            throw new BusineseException(errorCode, msg);
        }
    }
    public static void checkNullParams(Object object) {
        checkNullParams(object,  "传入参数为空");
    }
    public static void checkNullParams(Object object, String msg) {
        checkNull(object, ErrorCode.PARAMS_ERROR, msg);
    }
    public static void checkParams(boolean flag) {
        if (flag) {
            throw new BusineseException(ErrorCode.PARAMS_ERROR, "传入参数为空");
        }
    }
    public static void check(boolean flag, ErrorCode errorCode, String msg) {
        if (flag) {
            throw new BusineseException(errorCode, msg);
        }
    }

    /**
     * 判断某时间是否在两个时间之间
     *
     * @param startDate 开始时间
     * @param endDate 结束时间
     * @param currentDate 当前时间
     * @author yanzhen
     **/
    public static boolean isBetween(Date startDate, Date endDate, Date currentDate) {
        long startMillis = startDate.getTime();
        long endMillis = endDate.getTime();
        long currentMillis = currentDate.getTime();

        return currentMillis > startMillis && currentMillis < endMillis;
    }

}
